#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>

int global_val = 10;
int main(int argc, char const *argv[])
{

    int locate_val = 100;
    __pid_t pid = fork();
    printf("child process pid:%d\n",pid); 

    if (pid == 0)
    {
        printf("child process running...\n");
    }
    else
    {
        printf("father process running...\n");
    }

    if (pid == 0)
    {

    }
    else
    {
        int status;
        while(!waitpid(-1,&status,WNOHANG)){
            //这里运行父进程的代码段
           
        }
        if (WIFEXITED(status))
        {
            printf("子进程的退出返回值：%d \n",WEXITSTATUS(status));
        }
        printf("father global value:%d\n",global_val);
        printf("father locate value:%d\n",locate_val);
       
        sleep(30);
    }

    return 0;
}
